using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.Threading;

namespace FozDesk.Extensions
{
    public partial class SendKeysEx
    {
        #region API Calls
        // Get a handle to an application window.
        [DllImport("USER32.DLL")]
        private static extern IntPtr FindWindow(string lpClassName,
            string lpWindowName);

        // Activate an application window.
        [DllImport("USER32.DLL")]
        private static extern bool SetForegroundWindow(IntPtr hWnd);

        [DllImport("user32.dll")]
        private static extern void mouse_event(UInt32 dwFlags, UInt32 dx, UInt32 dy, UInt32 dwData, IntPtr dwExtraInfo);

        private const UInt32 MOUSEEVENTMOVE = 0x0001;
        private const UInt32 MOUSEEVENTLEFTDOWN = 0x0002;
        private const UInt32 MOUSEEVENTLEFTUP = 0x0004;
        #endregion

        #region Private Vars
        private const int INTERVAL = 200;
        private const int MAXRETRY = 50;
        private const string TIMEOUT = "Timeout: Exceeded maximum number of retries.";
        //xml commands
        private const string SEND = "send";
        private const string SENDWAIT = "sendwait";
        private const string WAIT = "wait";
        private const string LAUNCH = "launch";
        private const string FOCUS = "focus";
        private const string MOVE = "move";
        private const string CLICK = "click";
        private const string DBLCLICK = "dblclick";
        //xml attributes
        private const string ID = "id";
        private const string VALUE = "value";
        private const string X = "x";
        private const string Y = "y";
        private const string PROCESS = "process";
        private const string TITLE = "title";
        private const string DELAY = "delay";
        //window
        private IntPtr _WindowHandle;
        private String _WindowClass;
        private String _WindowCaption;
        #endregion

        #region Base Members
        public void Send(string Keys)
        {
            SendKeys.Send(Keys);
        }

        public void SendWait(string Keys)
        {
            SendKeys.SendWait(Keys);
        }

        public void Sleep()
        {
            Thread.Sleep(INTERVAL);
        }

        public void Sleep(Int32 Interval)
        {
            Thread.Sleep(Interval);
        }
        #endregion
    }
}
